<template>
  <t-row :gutter="[16, 16]">
    <t-col :xs="6" :xl="3" v-for="(item, index) in panelList" :key="item.title">
      <t-card
          :bordered="false"
          :title="item.title"
          :style="{ height: '168px' }"
          :class="{ 'dashboard-item': true, 'dashboard-item--main-color': index == 0 }"
      >
        <div class="dashboard-item-top">
          <span :style="{ fontSize: `${resizeTime * 36}px` }">{{ item.number }}</span>
        </div>
        <div class="dashboard-item-left">
           <span v-if="index === 0" :style="{ marginTop: `-24px` }">
            <usergroup-icon/>
          </span>
          <span v-else-if="index === 1" :style="{ marginTop: `-24px` }">
            <home-icon/>
          </span>
          <span v-else-if="index === 2" :style="{ marginTop: `-24px` }">
            <home-icon/>
          </span>
          <span v-else :style="{ marginTop: '-24px' }">
            <file-icon/>
          </span>
        </div>
        <template #footer>
          <div class="dashboard-item-bottom">
            <div class="dashboard-item-block" @click="handleNav(index)">
              详情
              <chevron-right-icon/>
            </div>
          </div>
        </template>
      </t-card>
    </t-col>
  </t-row>
</template>
<script>
import {UsergroupIcon, FileIcon, ChevronRightIcon,HomeIcon} from 'tdesign-icons-vue';

export default {
  name: 'TopPanel',
  components: {
    HomeIcon,
    UsergroupIcon,
    FileIcon,
    ChevronRightIcon,
  },
  methods:{
    handleNav(index) {
      if (index===0){
        this.$router.push('/owners').catch(err=>err);
      }else if (index===1){
        this.$router.push('/houses').catch(err=>err);
      }else if (index===2){
        this.$router.push('/buildings').catch(err=>err);
      }else {
        this.$router.push('/complains').catch(err=>err);
      }
    },
  },
  data() {
    return {
      resizeTime: 1,
      panelList: [
        {
          title: '住户数量',
          number: '300',
        },
        {
          title: '房屋数量',
          number: '400',
        },
        {
          title: '楼栋数量',
          number: '10',
        },
        {
          title: '待办事项',
          number: '15',
        },
      ]
    };
  },
}

</script>
<style lang="less" scoped>
@import '@/style/variables.less';

.dashboard-item {
  padding: 8px;

  /deep/ .t-card__footer {
    padding-top: 0;
  }

  /deep/ .t-card__title {
    font-size: 14px;
    font-weight: 500;
  }

  /deep/ .t-card__body {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    position: relative;
  }

  &:hover {
    cursor: pointer;
  }

  &-top {
    display: flex;
    flex-direction: row;
    align-items: flex-start;

    > span {
      display: inline-block;
      color: var(--td-text-color-primary);
      font-size: 36px;
      line-height: 44px;
    }
  }

  &-bottom {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    > .t-icon {
      cursor: pointer;
    }
  }

  &-block {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 22px;
    color: var(--td-text-color-placeholder);
  }

  &-trend {
    margin-left: 8px;
  }

  &-left {
    position: absolute;
    top: 0;
    right: 32px;

    > span {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 56px;
      height: 56px;
      background: var(--td-brand-color-1);
      border-radius: 50%;

      .t-icon {
        font-size: 24px;
        color: var(--td-brand-color);
      }
    }
  }

  // 针对第一个卡片需要反色处理
  &--main-color {
    background: var(--td-brand-color);
    color: var(--td-text-color-primary);

    /deep/ .t-card__title,
    .dashboard-item-top span,
    .dashboard-item-bottom {
      color: var(--td-text-color-anti);
    }

    .dashboard-item-block {
      color: var(--td-text-color-anti);
      opacity: 0.6;
    }

    .dashboard-item-bottom {
      color: var(--td-text-color-anti);
    }
  }
}
</style>
